﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKArchUtils.Utils;
using YJKAreaStatistic.Forms;
using YJKRevitBase.WinForm;
using YJKRevitView;

namespace YJKAreaStatistic
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	internal class CmdAreaStatistic : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			CmdViewType types = (CmdViewType)1935;
			if (SwitchView.SetUsableView(types, commandData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
            CmdAreaStatistic._hWndRevit = new WindowHandle(Process.GetCurrentProcess().MainWindowHandle);
			HideWarningAndErroringKit @object = new HideWarningAndErroringKit(new List<string>
			{
				"CreateNewArea"
			}, HideWarningAndErroringKit.HideKitEnum.HideWarning);
			commandData.Application.Application.FailuresProcessing += @object.OnFailuresProcessing;
			try
			{
				this.m_useForm = new AreaStatisticResultForm(commandData, CmdAreaStatistic._hWndRevit, commandData.Application.ActiveUIDocument);
				this.m_useManger = new AreaStatisticFormModellessManger(this.m_useForm);
				this.m_useManger.DoLoopWork();
			}
			catch
			{
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

        public static WindowHandle _hWndRevit;

		private AreaStatisticResultForm m_useForm;

		private AreaStatisticFormModellessManger m_useManger;
	}
}
